<template>
  <div style="padding-top: 10px">
    <!--页面表单/表格显示-->
    <div v-for="(item, index) in type" :key="index">
      <!--1 tab标签页切换标题-->
      <!--<Tabs :option="tabsOption" v-if="item === 'tabs'" @change="changeTabsMethods"></Tabs>-->
      <!--1 tab标签页切换内容-->
      <div class="tabsChangeContent" v-if="item === 'tabs'">
        <!--循环遍历-->
        <el-tabs @tab-click="changeTabsMethods" v-model="tabsActiveName">
          <el-tab-pane v-for="(item1) in tabsOption.column" :key="item1.prop" :label="item1.label" :name="item1.prop"
                       v-show="changeTabOption.prop === item1.prop">
            <div v-for="(item2, index2) in item1.type" :key="item1.prop + index2">
              <SimpleData :simpleData="simpleData" :option="simpleOption" :buttonSelf="simpleButtonArray"
                          @selfButton="simpleButton" v-if="item2 === 'simpleData'"></SimpleData>
              <avue-crud
                v-if="item2 === 'table'"
                :option="tableOption"
                :data="tableData"
                :page="tablePage"
                :key="tabName"
                :table-loading="loading"
                @search-change="search"
                @search-reset="searchClear"
                @size-change="sizeChangeSearch"
                @current-change="currentChangeSearch">
                <template slot="searchMenu">
                  <el-button size="small" v-for="(item,index) in tableButtonArray" :key="'cc' + index"
                             @click="tableButton(item.prop)">{{item.label}}
                  </el-button>
                </template>
                <template slot-scope="scope" slot="menu">
                  <el-button size="small" type="text"
                             @click.native="selfMenuAction(scope.row, tableOption.selfMenuButton)"
                             v-if="tableOption.selfMenuButton == 'msg'">补发
                  </el-button>
                </template>
              </avue-crud>
              <CommonForm v-if="item2 === 'form'" :option="formOption" @submitForm="submitForm"></CommonForm>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <!--2 simple组件-->
      <SimpleData :simpleData="simpleData" :option="simpleOption" :buttonSelf="simpleButtonArray"
                  @selfButton="simpleButton" v-if="item === 'simpleData'"></SimpleData>
      <!--3 表单组件-->
      <CommonForm v-if="item === 'form'" :option="formOption" @submitForm="submitForm"></CommonForm>
      <!--4 表格组件-->
      <avue-crud
        v-if="item === 'table'"
        :option="tableOption"
        :data="tableData"
        :page="tablePage"
        :key="nameFlag"
        :table-loading="loading"
        @search-change="search"
        @search-reset="searchClear"
        @sort-change="sortChange"
        @expand-change="expandChange"
        @size-change="sizeChangeSearch"
        @current-change="currentChangeSearch">
        <template slot="searchMenu">
          <el-button size="small" v-for="(item,index) in tableButtonArray" :key="index" @click="tableButton(item.prop)">
            {{item.label}}
          </el-button>
        </template>
        <template slot="expand" slot-scope="{row}">
          {{expandContent}}
        </template>
      </avue-crud>
    </div>
    <!--弹框显示-->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      :close-on-click-modal="true"
      :close-on-press-escape="true"
      :show-close="true"
      top="5%"
      width="90%">
      <el-scrollbar style="height: 450px;">
        <avue-crud
          v-if="dialogType === 'table'"
          :option="dialogTableOptions"
          :key="mathRandom"
          :table-loading="dialogLoading"
          :data="dialogTableData"
          @search-change="dialogSearch"
          @search-reset="dialogSearchClear">
          <template slot-scope="scope" slot="menu">
            <el-button
              size="small"
              type="text"
              v-for="(item,index) in dialogTableButtonArray"
              :key="index"
              @click="tableButton(item.prop, scope.row)">
              {{item.label}}
            </el-button>
          </template>
        </avue-crud>
        <SimpleData :simpleData="dialogSimpleData" :option="dialogSimpleOptions" :buttonSelf="dialogSimpleButtonArray"
                    @selfButton="simpleButton" v-if="dialogType === 'simpleData'"></SimpleData>
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogTemplateConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import Tabs from '@/components/common/Tabs'
  import SimpleData from '@/components/common/SimpleData'
  import CommonTable from '@/components/common/CommonTable'
  import CommonForm from '@/components/common/CommonDate'
  import {queryLoss, sendContentMessage, saveTransTraffic} from '@/api/bankBiz/loss/loss'

  export default {
    name: 'accSearch',
    components: {
      Tabs,
      SimpleData,
      CommonTable,
      CommonForm
    },
    data() {
      return {
        tabsActiveName: '',
        namespace: '',
        nameFlag: '',
        type: [],
        waitData: true,
        // tabsData
        tabsOption: {},
        changeTabOption: {},
        // simpleData
        simpleData: {},
        simpleOption: {},
        simpleButtonArray: [],
        // tableData
        tableOption: {},
        tableData: [],
        tableTotalData: [],
        tablePage: {},
        tableButtonArray: [],
        // formData
        formOption: {},
        formButtonArray: [],
        // queryBody
        query: {
          'namespace': '',
          'key': ''
        },
        returnType: [],
        tabName: '',
        loading: false,
        expandContent: '',
        dialogVisible: false,
        dialogWaitData: true,
        dialogOptions: {},
        dialogTitle: '',
        dialogType: 'table',
        dialogTableOptions: {},
        dialogTableData: [],
        dialogTableButtonArray: [],
        dialogSimpleOptions: {},
        dialogSimpleData: {},
        dialogSimpleButtonArray: [],
        dialogQuery: {
          'namespace': '',
          'key': ''
        },
        mathRandom: '',
        dialogLoading: false
      }
    },
    created() {
      this.initOptions()
    },
    mounted() {
      let self = this
      // 收到短信银行验密结果刷新数据
      window.eventEmitter.$on('EventMsgBank', (data) => {
        if ('01' == data.p_biz && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '短信银行签约成功！', 'success')
        } else if ('01' == data.p_biz && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '短信银行签约失败！', 'error')
        } else if ('02' == data.p_biz && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '短信银行变更成功！', 'success')
        } else if ('02' == data.p_biz && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '短信银行变更失败！', 'error')
        } else if ('03' == data.p_biz && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '短信银行关闭成功！', 'success')
        } else if ('03' == data.p_biz && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '短信银行关闭失败！', 'error')
        } else if ('04' == data.p_biz && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          var message = ''
          if (data.p_cert_num) {
            message = data.p_cert_num.replace(/\\/g,'').replace(/"/g,'').replace(/,/g, ';')
          }
          window.globalUiKit.notify('提示', message, 'success')
        } else if ('04' == data.p_biz && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '短信银行一键关闭失败！', 'error')
        }
      })
      // 收到查询密码业务结果刷新数据
      window.eventEmitter.$on('EventPassUpdate', (data) => {
        if ('02' == data.p_pass_operate && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '查询密码设置成功！', 'success')
        } else if ('02' == data.p_pass_operate && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '查询密码设置失败！', 'error')
        } else if ('03' == data.p_pass_operate && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '查询密码重置成功！', 'success')
        } else if ('03' == data.p_pass_operate && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '查询密码重置失败！', 'error')
        } else if ('04' == data.p_pass_operate && '01' == data.p_msgBankFlag) {
          self.commonQueryData()
          window.globalUiKit.notify('提示', '查询密码修改成功！', 'success')
        } else if ('04' == data.p_pass_operate && '01' != data.p_msgBankFlag) {
          window.globalUiKit.notify('提示', '查询密码修改失败！', 'error')
        }
      })
    },
    beforeDestroy() {
      window.eventEmitter.$off('EventMsgBank')
      window.eventEmitter.$off('EventPassUpdate')
    },
    methods: {
      // 初始化配置
      initOptions() {
        this.namespace = this.$route.path.split('/')[1]
        // 首字母大写
        this.namespace = this.namespace.substring(0, 1).toUpperCase() + this.namespace.substring(1)
        this.nameFlag = this.$route.path.split('/')[2]
        if (!this.nameFlag) {
          console.log('nameFlag is not exist!')
          return
        }
        this.type = this.$route.meta.type
        this.returnType = this.$route.meta.type
        this.waitData = this.$route.meta.waitData
        console.log('receive params is: ' + this.namespace + ', ' + this.nameFlag)
        let commonOptions = ''
        if ('Personal' === this.namespace) {
          commonOptions = personalOptions
          // window.personalOptions.moduleOption.accountOption.checkedFlag = false
        } else if ('Company' === this.namespace) {
          commonOptions = companyOptions
          // window.personalOptions.moduleOption.accountOption.checkedFlag = false
        } else if ('PublicInfo' === this.namespace) {
          commonOptions = publicOptions
        } else if ('ReportLoss' === this.namespace) {
          commonOptions = personalOptions
        }
        // 循环组件，初始化赋值
        for (let i = 0; i < this.type.length; i++) {
          // 1 页签初始化
          if ('tabs' === this.type[i]) {
            let tabsViewOption = commonOptions.tabsViewOption
            this.tabsOption = tabsViewOption[this.nameFlag].tabsOption
            // 默认第一个页签
            this.tabsActiveName = this.tabsOption.column[0].prop
            this.changeTabOption.prop = this.tabsOption.column[0].prop
            this.returnType = this.tabsOption.column[0].type
            this.waitData = this.tabsOption.column[0].waitData
            this.dialogOptions = this.tabsOption.column[0].detailOptions
            // 初始化第一个页签配置
            for (let j = 0; j < this.tabsOption.column[0].type.length; j++) {
              if ('table' == this.tabsOption.column[0].type[j]) {
                this.tableOption = this.tabsOption.column[0].tableOptions
                this.tablePage = this.tabsOption.column[0].tablePage
                this.tableButtonArray = this.tabsOption.column[0].tableButtonArray
              } else if ('simpleData' == this.tabsOption.column[0].type[j]) {
                this.simpleOption = this.tabsOption.column[0].simpleOptions
                this.simpleButtonArray = this.tabsOption.column[0].simpleButtonArray
              } else if ('form' == this.tabsOption.column[0].type[j]) {
                this.formOption = this.tabsOption.column[0].formOptions
                this.formButtonArray = this.tabsOption.column[0].formButtonArray
              }
            }

            if (this.tabsOption.column[0].query) {
              this.query.query = Object.assign({}, this.tabsOption.column[0].query)
            }
            this.query.namespace = this.namespace
            this.query.key = this.tabsOption.column[0].prop
          }
          // 2 表单初始化
          else if ('form' === this.type[i]) {
            let formViewOption = commonOptions.formViewOption
            this.formOption = formViewOption[this.nameFlag].formOptions
            this.formButtonArray = formViewOption[this.nameFlag].formButtonArray
            if (formViewOption[this.nameFlag].query) {
              this.query.query = Object.assign({}, formViewOption[this.nameFlag].query)
            }
            this.query.namespace = this.namespace
            this.query.key = this.nameFlag

          }
          // 3 表格初始化
          else if ('table' === this.type[i]) {
            let tableViewOption = commonOptions.tableViewOption
            this.tableOption = tableViewOption[this.nameFlag].tableOptions
            this.waitData = tableViewOption[this.nameFlag].waitData
            this.tablePage = tableViewOption[this.nameFlag].tablePage
            this.tableButtonArray = tableViewOption[this.nameFlag].tableButtonArray
            if (tableViewOption[this.nameFlag].query) {
              this.query.query = Object.assign({}, tableViewOption[this.nameFlag].query)
            }
            this.query.namespace = this.namespace
            this.query.key = this.nameFlag
            this.query.query = {
              'pageSize': this.query.query.pageSize,
              'currentPage': this.query.query.currentPage
            }
          }
          // 4 simple初始化
          else if ('simpleData' === this.type[i]) {
            let simpleViewOption = commonOptions.simpleViewOption
            this.simpleButtonArray = simpleViewOption[this.nameFlag].simpleButtonArray
            this.simpleOption = simpleViewOption[this.nameFlag].simpleOptions
            if (simpleViewOption[this.nameFlag].query) {
              this.query.query = Object.assign({}, simpleViewOption[this.nameFlag].query)
            }
            this.query.namespace = this.namespace
            this.query.key = this.nameFlag
          }
        }
        this.commonQueryData(this.waitData)
      },
      // 切换页签
      changeTabsMethods(tab, event) {
        console.log(tab, event)
        this.tabName = tab.name
        let data = []
        for (let i = 0; i < this.tabsOption.column.length; i++) {
          if (this.tabsOption.column[i].prop === this.tabsActiveName) {
            data = this.tabsOption.column[i]
          }
        }
        this.changeTabOption = data
        if (data.query) {
          this.query.query = Object.assign({}, data.query)
        }
        this.query.key = data.prop
        this.returnType = data.type
        this.dialogOptions = data.detailOptions
        for (let i = 0; i < data.type.length; i++) {
          if ('table' == data.type[i]) {
            this.tableOption = data.tableOptions
            this.tablePage = data.tablePage
            this.tableButtonArray = data.tableButtonArray
            this.tableData = []
            this.tableTotalData = []
          } else if ('simpleData' == data.type[i]) {
            this.simpleOption = data.simpleOptions
            this.simpleButtonArray = data.simpleButtonArray
          } else if ('form' == data.type[i]) {
            this.formOption = data.formOptions
            this.formButtonArray = data.formButtonArray
          }
        }
        this.commonQueryData()
      },
      // 公用组件接口
      commonQueryData(waitData) {
        if (waitData) {
          return
        }
        console.log('公用组件接口')
        // loading
        this.loading = true
        // 卡号/账户号
        if ('PublicInfo' != this.namespace) {
          this.query.query.accountNo = sessionStorage.getItem('bankNo') || this.$store.getters.GET_GLOBALCARDNO
          if (!this.query.query.accountNo) {
            window.globalUiKit.notify('提示', '暂未获取到卡号，请返回到交易首页重新进入子交易！', 'error')
            return
          }
        }
        // 汇率查询-汇率日期
        if (this.query.query.exchangeRateDateSearch) {
          let exchangeRateDate = this.query.query.exchangeRateDateSearch
          this.query.query.exchangeRateDate = [exchangeRateDate, exchangeRateDate]
        }
        // 存款利率查询
        if ('depositInterestRateInquiry' == this.query.key) {
          // 默认币种为人民币
          if (!this.query.query.currency) {
            this.query.query.currency = '11'
          }
          // 存款方式为大额存单
          if ('110' != this.query.query.depositMethod) {
            delete this.query.query.area
          }
        }
        // 查询密码修改
        else if ('passUpdate' == this.query.key) {
          this.query.query.accountNo = sessionStorage.getItem('customerNo')
        }
        // 初始化分页参数
        this.query.query.currentPage = 1
        this.query.query.pageSize = 20
        this.tablePage.currentPage = 1
        this.tablePage.pageSize = 20
        this.tablePage.total = 0
        // 调用公共业务接口
        queryLoss(this.query).then((res) => {
          console.log('response data is: ' + JSON.stringify(res.data))
          this.loading = false
          if (200 == res.data.code) {
            for (let i = 0; i < this.returnType.length; i++) {
              if ('table' == this.returnType[i]) {
                if (res.data.data.resList == null || res.data.data.resList == undefined) {
                  this.tableData = []
                  this.tableTotalData = []
                  this.tablePage.total = 0
                  return
                }
                this.tableData = res.data.data.resList
                this.tableTotalData = res.data.data.resList
                // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
                if ('personalProductSupermarket' == this.query.key || 'wealthProductSupermarket' == this.query.key || 'wealthCurrentHeld' == this.query.key || 'wealthCurrentTrust' == this.query.key || 'fundProductSupermarket' == this.query.key) {
                  console.log(parseInt(res.data.data.totalNum))
                  this.tablePage.total = parseInt(res.data.data.totalNum)
                  return
                }
                // 兼容客户端分页
                if ('Client' == window.Settings.pageType) {
                  this.tableData = this.tableTotalData.slice((this.tablePage.currentPage - 1) * this.tablePage.pageSize, this.tablePage.currentPage * this.tablePage.pageSize)
                  this.tablePage.total = this.tableTotalData.length
                }
              } else if ('simpleData' == this.returnType[i]) {
                this.simpleData = res.data.data
                console.log('key is: ' + this.query.key)
                if ('messageService' == this.query.key) {
                  // 短信银行 0 未开通，1 已开通
                  if ('0' == this.simpleData.status) {
                    this.simpleButtonArray[0].hide = window.Settings.msgServiceSwitch ? false : true
                    this.simpleButtonArray[1].hide = true
                    this.simpleButtonArray[2].hide = true
                    this.simpleButtonArray[3].hide = true
                    this.simpleButtonArray[4].hide = true
                  } else {
                    this.simpleButtonArray[0].hide = true
                    this.simpleButtonArray[1].hide = window.Settings.msgServiceSwitch ? false : true
                    this.simpleButtonArray[2].hide = window.Settings.msgServiceSwitch ? false : true
                    this.simpleButtonArray[3].hide = window.Settings.msgServiceSwitch ? false : true
                    this.simpleButtonArray[4].hide = false
                  }
                } else if ('passUpdate' == this.query.key) {
                  // 短信银行 0 未开通，1 已开通
                  if ('0' == this.simpleData.passStatus) {
                    this.simpleButtonArray[0].hide = false
                    this.simpleButtonArray[1].hide = true
                    this.simpleButtonArray[2].hide = true
                  } else {
                    this.simpleButtonArray[0].hide = true
                    this.simpleButtonArray[1].hide = false
                    this.simpleButtonArray[2].hide = false
                  }
                }
              } else if ('form' == this.returnType[i]) {

              }
            }
            saveTransTraffic(this.query.namespace + '-' + this.query.key, '成功', '')
          } else {
            let errMsg = res.data.message
            window.globalUiKit.notify('提示', errMsg, 'error')
            saveTransTraffic(this.query.namespace + '-' + this.query.key, '失败', errMsg)
            this.simpleData = {}
            this.tableData = []
            this.tableTotalData = []
            this.tablePage.total = 0
          }
        }).catch((err) => {
          saveTransTraffic(this.query.namespace + '-' + this.query.key, '失败', '')
          this.loading = false
          this.simpleData = {}
          this.tableData = []
          this.tableTotalData = []
          this.tablePage.total = 0
          console.log(err)
        })
      },
      searchData(sel){
      console.log('sel is: ' + sel)
      this.selectData = sel
      },
      // 搜索
      search(params, done) {
        console.log('search conditions params is：' + JSON.stringify(params))
        this.getListByKey(params, done)
      },
      // 表格自定按钮事件
      tableButton(prop, row) {
        console.log('prop is: ' + prop + ', row is: ' + JSON.stringify(row))
        // 最近10笔
        if (prop == 'personal-detailSearchData-tenCount') {
          this.query.query['count'] = 10
          this.query.query['transferDate'] = [new Date(new Date().setDate(new Date().getDate() - 90)).Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
          this.query.query['accountNo'] = sessionStorage.getItem('bankNo')
          this.commonQueryData()
        } else if (prop == 'company-detailSearchData-tenCount') {
          this.query.query['count'] = 10
          this.query.query['transferDate'] = [new Date(new Date().setDate(new Date().getDate() - 90)).Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
          this.query.query['accountNo'] = sessionStorage.getItem('bankNo')
          this.commonQueryData()
        }
        // 最近10日
        else if (prop == 'personal-detailSearchData-tenDay') {
          this.query.query['count'] = 100
          this.query.query['transferDate'] = [new Date(new Date().setDate(new Date().getDate() - 10)).Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
          this.query.query['accountNo'] = sessionStorage.getItem('bankNo')
          this.commonQueryData()
        } else if (prop == 'company-detailSearchData-tenDay') {
          this.query.query['count'] = 100
          this.query.query['transferDate'] = [new Date(new Date().setDate(new Date().getDate() - 10)).Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
          this.query.query['accountNo'] = sessionStorage.getItem('bankNo')
          this.commonQueryData()
        }
        // 短信银行业务-重发
        else if (prop == 'personal-messageService-sendMsg') {
          this.$confirm(row.sms_content, '短信发送', {
            confirmButtonText: '发送',
            cancelButtonText: '取消',
            type: ''
          }).then(() => {
            let params = {
              'content': row.sms_content,
              'phone': row.phone,
              'agentName': Constants.Agent.agentName,
              'agentId': Constants.Agent.agentId,
              'smsType': '综合业务'
            }
            sendContentMessage(params).then(res => {
              if (200 == res.data.code) {
                window.globalUiKit.notify('提示', '短信发送成功！', 'success')
              } else {
                window.globalUiKit.alert('短信发送失败', '失败原因：' + res.data.message + '；入参：' + JSON.stringify(params))
              }
            }).catch(error => {
              console.log(error)
              window.globalUiKit.alert('短信发送失败', '失败原因：' + error + '；入参：' + JSON.stringify(params))
            })
          }).catch(() => {
            console.log('取消发送！')
          });
        }
      },
      // simpleData自定义事件
      simpleButton(prop) {
        console.log('prop is: ' + prop)
        // 开户行及预留手机号码查询
        if (prop == 'personal-telReservationData-sendMsg') {
          let params = {
            'content': '尊敬的客户您好，您的开户行信息如下，开户行名称：' + this.simpleData.openBankName +
            '；开户行地址：' + this.simpleData.address + '；大额行号：' + this.simpleData.largeNum +
            '；开户行电话：' + this.simpleData.phone + '；预留手机号：' + this.simpleData.telReservation,
            'phone': this.simpleData.telReservation,
            'agentName': Constants.Agent.agentName,
            'agentId': Constants.Agent.agentId,
            'smsType': '综合业务'
          }
          sendContentMessage(params).then(response => {
            if (200 == response.data.code) {
              console.log('send message success')
            }
          }).catch(error => {
            console.log(error)
          })
        }
        // 短信银行签约
        else if (prop == 'personal-messageService-set') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起签约请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '01', // 密码类型
            'p_pass_operate': '01', // 交易密码操作
            'p_biz': '01', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 短信银行变更
        else if (prop == 'personal-messageService-change') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起变更请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '01', // 密码类型
            'p_pass_operate': '01', // 交易密码操作
            'p_biz': '02', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 短信银行关闭
        else if (prop == 'personal-messageService-close') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起关闭请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '01', // 密码类型
            'p_pass_operate': '01', // 交易密码操作
            'p_biz': '03', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 短信银行一键关闭
        else if (prop == 'personal-messageService-oneClickClose') {
          if (!sessionStorage.getItem('bankNoList')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起一键关闭请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '05', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNoList') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '01', // 密码类型
            'p_pass_operate': '01', // 交易密码操作
            'p_biz': '04', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 短信银行重发短信
        else if (prop == 'personal-messageService-resend') {
          this.dialogTemplate('messageServerResend')
        }
        // 查询密码设置
        else if (prop == 'personal-passUpdate-set') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起密码设置请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '02', // 密码类型
            'p_pass_operate': '02', // 交易密码操作
            'p_biz': '00', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 查询密码重置
        else if (prop == 'personal-passUpdate-reset') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起密码重置请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '02', // 密码类型
            'p_pass_operate': '03', // 交易密码操作
            'p_biz': '00', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
        // 查询密码修改
        else if (prop == 'personal-passUpdate-update') {
          if (!sessionStorage.getItem('bankNo')) {
            window.globalUiKit.notify('提示', '获取卡号信息为空，不能发起密码修改请求！', 'error')
            return
          }
          let userdata = {
            // 私有部分，根据不同验证类型组合
            'p_verifytype': '02', // 验密类型
            'p_cert_type': '01', // 介质类型
            'p_cert_num': sessionStorage.getItem('bankNo') || '', // 介质号码
            'p_accno': '', // 对公客户号
            'p_oper_id': '', // 对公操作员ID
            'p_pass_type': '02', // 密码类型
            'p_pass_operate': '04', // 交易密码操作
            'p_biz': '00', // 业务操作
            // 公共部分
            'r_function': 'singletransfer',
            'r_flag': '3',
            'con_flag': '1'
          }
          globalUserData.verifyPass(userdata)
        }
      },
      // 表单自定义按钮事件
      formButton(prop) {
        buttonAction.selfFunHandler(prop)
      },
      // 切换行数
      sizeChangeSearch(val) {
        this.query.query.currentPage = 1
        this.query.query.pageSize = val
        // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
        if ('personalProductSupermarket' == this.query.key || 'wealthProductSupermarket' == this.query.key || 'wealthCurrentHeld' == this.query.key || 'wealthCurrentTrust' == this.query.key || 'fundProductSupermarket' == this.query.key) {
          queryLoss(this.query).then((res) => {
            if(res.data.code == 200){
              this.tablePage.total = parseInt(res.data.data.totalNum)
              this.tableData = res.data.data.resList
            }else{
              this.tablePage.total = 0
              this.tableData = []
              window.globalUiKit.notify('提示', res.data.message, 'error')
            }
          }).catch((err) => {
            console.log(err)
          })
          return
        }
        // 兼容客户端分页
        if ('Client' == window.Settings.pageType) {
          this.tablePage.currentPage = 1
          this.tablePage.pageSize = val
          this.tableData = this.tableTotalData.slice((this.tablePage.currentPage - 1) * this.tablePage.pageSize, this.tablePage.currentPage * this.tablePage.pageSize)
          this.tablePage.total = this.tableTotalData.length
          return
        }
      },
      // 切换页码
      currentChangeSearch(val) {
        this.query.query.currentPage = val
        console.log('切换页码')
        // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
        if ('personalProductSupermarket' == this.query.key || 'wealthProductSupermarket' == this.query.key || 'wealthCurrentHeld' == this.query.key || 'wealthCurrentTrust' == this.query.key || 'fundProductSupermarket' == this.query.key) {
          queryLoss(this.query).then((res) => {
            if(res.data.code == 200){
              this.tablePage.total = parseInt(res.data.data.totalNum)
              this.tableData = res.data.data.resList
            }else{
              this.tablePage.total = 0
              this.tableData = []
              window.globalUiKit.notify('提示', res.data.message, 'error')
            }

          }).catch((err) => {
            console.log(err)
          })
          return
        }
        // 兼容客户端分页
        if ('Client' == window.Settings.pageType) {
          this.tablePage.currentPage = val
          this.tableData = this.tableTotalData.slice((this.tablePage.currentPage - 1) * this.tablePage.pageSize, this.tablePage.currentPage * this.tablePage.pageSize)
          this.tablePage.total = this.tableTotalData.length
          return
        }
      },
      // 搜索条件清空回调
      searchClear() {
        this.query.query = {
          'pageSize': 20,
          'currentPage': 1
        }
      },
      // 表单提交
      submitForm(data, done) {
        this.$message.success('当前数据' + JSON.stringify(data))
        this.commonQueryData()
        if (done) {
          done()
        }
      },
      // 表格搜索查询
      getListByKey(params, done) {
        if ('detailSearchData' == this.query.key) {
          this.query.query.count = ''
          this.query.query.transferDate = [new Date(new Date().setDate(new Date().getDate() - 90)).Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
          this.query.query.accountNo = sessionStorage.getItem('bankNo')
          if (params && params.transferDate) {
            // 交易日期范围不能超过一年
            if ('Personal' === this.query.namespace) {
              if (Utils.dateRange(params.transferDate[0], params.transferDate[1]) > 365) {
                window.globalUiKit.notify('提示', '交易日期范围不能超过一年！', 'error')
                done()
                return
              }
            } else {
              if (Utils.dateRange(params.transferDate[0], params.transferDate[1]) > 90) {
                window.globalUiKit.notify('提示', '交易日期范围不能超过三个月！', 'error')
                done()
                return
              }
            }
            // 交易日期开始时间不能超过五年
            if (Utils.dateRange(params.transferDate[0], new Date().Format('yyyyMMdd')) > 1826) {
              window.globalUiKit.notify('提示', '交易日期开始时间不能超过五年！', 'error')
              done()
              return
            }
          }
        }
        if ('depositInterestRateInquiry' == this.query.key) {
          this.query.query.currency = ''
          this.query.query.depositMethod = ''
        }
        Object.keys(params).forEach(keys => {
          if (params[keys]) {
            this.query.query[keys] = params[keys]
          }
        })
        this.commonQueryData()
        if (done) {
          done()
        }
      },
      // 表格排序
      sortChange(row) {
        console.log(JSON.stringify(row))
        // 金融信息-理财产品超市
        if ('wealthProductSupermarket' == this.query.key) {
          this.query.query = {
            'currentPage': 1,
            'pageSize': 20
          }
          // 升序(ascending)、降序(descending)、无序(null)
          if (row.order == 'descending' || row.order == null) {
            this.query.query[row.prop] = 0
          } else {
            this.query.query[row.prop] = 1
          }
          this.commonQueryData()
        }
      },
      // 行展开
      expandChange(row, expendList) {
        this.expandContent = ''
        this.tableOption.expandRowKeys = []
        if (expendList.length && row) {
          this.tableOption.expandRowKeys.push(row.productCode)
          let params = {
            'namespace': this.namespace,
            'key': 'productInstruction',
            'query': {
              'productCode': row.productCode
            }
          }
          queryLoss(params).then((res) => {
            if (200 == res.data.code && res.data.data && res.data.data.content) {
              this.expandContent = Utils.filterText(res.data.data.content)
            } else {
              window.globalUiKit.notify('提示', res.data.message, 'error')
            }
          }).catch((err) => {
            console.log(err)
          })
        }
      },
      /****************************************** 弹框详情相关 ***********************************/
      // 弹框dialog模板渲染
      dialogTemplate(nameFlag) {
        // 清空数据变量
        // 重新初始化数据
        this.dialogVisible = true
        this.mathRandom = Math.random()*10
        this.dialogTitle = this.dialogOptions[nameFlag].title
        this.dialogWaitData = this.dialogOptions[nameFlag].waitData
        for (let j = 0; j < this.dialogOptions[nameFlag].type.length; j++) {
          this.dialogType = this.dialogOptions[nameFlag].type[j]
          if ('table' == this.dialogOptions[nameFlag].type[j]) {
            this.dialogTableOptions = this.dialogOptions[nameFlag].tableOptions
            this.dialogTableButtonArray = this.dialogOptions[nameFlag].tableButtonArray
          } else if ('simpleData' == this.dialogOptions[nameFlag].type[j]) {
            this.dialogSimpleOptions = this.dialogOptions[nameFlag].simpleOptions
            this.dialogSimpleButtonArray = this.dialogOptions[nameFlag].simpleButtonArray
          }
        }
        this.dialogQuery.namespace = this.namespace
        this.dialogQuery.key = this.dialogOptions[nameFlag].prop
        this.dialogQuery.query = Object.assign({}, this.dialogOptions[nameFlag].query)
        this.commonDetailQueryData(this.dialogWaitData)
      },
      dialogTemplateConfirm() {
        this.dialogVisible = false
        this.dialogQuery.query = {}
      },
      // 详情搜索
      dialogSearch(params, done) {
        console.log('detail params: ' + JSON.stringify(params))
        // 短信重发
        if ('messageServiceListData' == this.dialogQuery.key) {
          this.dialogQuery.query.transferDate = [new Date().Format('yyyyMMdd'), new Date().Format('yyyyMMdd')]
        }
        Object.keys(params).forEach(keys => {
          if (params[keys]) {
            this.dialogQuery.query[keys] = params[keys]
          }
        })
        this.commonDetailQueryData()
        if (done) {
          done()
        }
      },
      // 详情清空
      dialogSearchClear() {
        this.dialogQuery.query = {}
      },
      // 调用详情弹框接口
      commonDetailQueryData(dialogWaitData) {
        if (dialogWaitData) {
          return
        }
        // loading加载
        this.dialogLoading = true
        if ('messageServiceListData' == this.dialogQuery.key) {
          this.dialogQuery.query.phone = sessionStorage.getItem('customerPhone')
        }
        queryLoss(this.dialogQuery).then((res) => {
          this.dialogLoading = false
          if(res.data.code == 200){
            if ('table' == this.dialogType) {
              this.dialogTableData = res.data.data.resList
            } else if ('simpleData' == this.dialogType) {
              this.dialogSimpleData = res.data.data
            }
          }else{
            this.dialogSimpleData = {}
            this.dialogTableData = []
            window.globalUiKit.notify('提示', res.data.message, 'error')
          }
        }).catch((err) => {
          console.log(err)
          this.dialogLoading = false
        })
      },
      // 初始化页面配置
      clearOption() {
        this.namespace = ''
        this.nameFlag = ''
        this.type = []
        this.waitData = true
        // tabsData
        this.tabsOption = {}
        this.changeTabOption = {}
        // simpleData
        this.simpleData = {}
        this.simpleOption = {}
        this.simpleButtonArray = []
        // tableData
        this.tableOption = {}
        this.tableData = []
        this.tablePage = {}
        this.tableButtonArray = []
        // tableData
        this.formOption = {}
        this.formButtonArray = []
        // queryBody
        this.query = {
          'namespace': '',
          'key': ''
        }
        this.returnType = []
        this.expandContent = ''
        this.dialogType = 'table'
        this.dialogVisible = false
        this.dialogWaitData = true
        this.dialogOptions = {}
        this.dialogTitle = ''
        this.dialogTableOptions = {}
        this.dialogTableData = []
        this.dialogTableButtonArray = []
        this.dialogSimpleOptions = {}
        this.dialogSimpleData = {}
        this.dialogSimpleButtonArray = []
        this.dialogQuery = {
          'namespace': '',
          'key': ''
        }
      },
      // 自定义菜单
      selfMenuAction(row, selfProp) {
        // 短信补发
        if ('msg' == selfProp) {
          console.log('msg row is: ' + JSON.stringify(row))
        }
      }
    },
    // 当前组件路由守卫
    beforeRouteEnter(to, from, next) {
      to.meta.currentComponentFlag = true
      next()
    },
    beforeRouteLeave(to, from, next) {
      this.$destroy()
      next();
    },
    // 初始化, TODO 优化，是否keep alive
    // watch: {
    //   '$route'(to, from) {
    //    访问当前组件，且上一次访问路径与本次访问路径不同
    //    if (to.meta.currentComponentFlag && this.cachePath !== to.path) {
    //       this.clearOption()
    //       this.initOptions()
    //       this.cachePath = to.path
    //     }
    //   }
    // }
  }
</script>

<style scoped>

</style>
